﻿using System.Runtime.CompilerServices;

namespace _4_2
{
    internal class Program
    {
        public delegate void TimerHandler(object sender,TimeEventArgs args);
        public class TimeEventArgs
        {
            public int Timers { get; set; }
        }
        public class Timer
        {
            public event TimerHandler Tick;
            public event TimerHandler Alarm;
            public void Time(int z)
            {
                Console.WriteLine("The timer will ring after"+ z+"s");
                TimeEventArgs args = new TimeEventArgs() { Timers =z };
                Tick(this, args);
                Alarm(this, args);
            }
        }
        public class Form
        {
            public Timer time1=new Timer();
            public Form()
            {
                time1.Tick += new TimerHandler(Time_Tick);
                time1.Alarm+=new TimerHandler(Time_Alarm);
                void Time_Tick(object sender, TimeEventArgs args)
                {
                    while (args.Timers != 0 )
                    {
                        
                        Console.WriteLine("嘀嗒");
                        args.Timers--;
                    }
                }
                void Time_Alarm(object sender, TimeEventArgs args)
                {
                    if(args.Timers == 0)
                    {
                        Console.WriteLine("铃铃铃");
                    }
                }
            }
        }
        static void Main(string[] args)
        {
            Form form1 = new Form();
            Console.WriteLine("Please enter the time:");
            string s=Console.ReadLine();
            int n = int.Parse(s);
            form1.time1.Time(n);
        }
    }
}
